/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import beanInfo.users;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import project.Admin;
import project.Login;
import project.Manager;

/**
 *
 * @author lyan
 */
public class loginControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listVaLues = new ArrayList<String>();

    public void checklogin(users us) {
        try {
            String sql = "select * from Users where "
                    + "UserName= '" + us.getUserName() + "' and Password='" + us.getPassWord() + "'";
            System.out.println(sql);

            ResultSet rs = JDBCHelper.excuteSelect(sql);

            if (rs.next()) {
                int role = rs.getInt("Roles");
                 String user=rs.getString("UserName");
                if (role==1)
                {
                   // System.out.println(rs.getString("Roles"));
                   
                    Admin ad = new Admin(user);
                    ad.setVisible(true);

                } 
                else {
                    // Admin ad = new Admin(us.getUserName());
                    Manager ma = new Manager(user);
                    ma.setVisible(true);
                    Login log = new Login();
                    log.setVisible(false);
                }
            }

        } catch (SQLException ex) {
            Helper.successMessage(" Login Faild", " Message");
        }

    }
}
